//去除左右两边空格
function strTrim(str){
	 return str.replace(/(^\s*)|(\s*$)/g, ""); 
}

//添加百度编辑器提示 Editor： 对象    hint： 提示文本
function addhint(Editor,hint){
		Editor.addListener("ready", function () {
			if(plainTxt(Editor)==""){
			loadEditorText(Editor,"",hint);
		}    
	});
	Editor.addListener("blur", function (type, event) {
		if(plainTxt(Editor)==""){
			loadEditorText(Editor,"",hint);
		}
	});
	Editor.addListener("afterFocus ", function (type, event) {
		var hintHtml='<div name="hint_zz" style="color: rgb(153, 153, 153);">'+hint+'</div>'
		if(plainTxt(Editor)==hintHtml)
			loadEditorText(Editor,"","");
	});
}





//切换国际化
function changeLocale(langType) {
	location.href = basePath + "/global?langType="+langType+"&targetUrl=" + location.href ;
}
//生成编辑器 id 编辑器id   宽度   高度   是否强制创建编辑器     编辑器最大字数限制
function newEditor(id,width,height,y,maxnum){
	var ue= UE.getEditor(id,{
			initialFrameWidth :width,//设置编辑器宽度
			initialFrameHeight:height,//设置编辑器高度
			autoHeightEnabled: true,
			focus:true, //是否焦点
			enterTag:'br' 
			},y);
	if(maxnum==null){//默认一万字
		maxnum=10000;
	}
	ue.addListener("keyup", function(type, event) {
		var count = ue.getContentLength(true);
		if(count>maxnum){
		var contentText = ue.getContentTxt();
		ue.setContent(contentText.substring(0, maxnum));
		}
	});
	
	//添加监听事件将百度编辑器初始化的p便签置空
	ue.addListener("focus", function (type, event) {
		console.log(ue.getContent());
	    if ($.trim(ue.getContent()) == "") {
	    	ue.setContent("");
	    }

	});
	return ue;
};
//替换回车
function TransferString(content)  
{  
    var string = content;  
    try{  
        string=string.replace(/\r\n/g,"<p>")  
        string=string.replace(/\n/g,"<p>");  
    }catch(e) {  
        alert(e.message);  
    }  
    return string;  
}

//获取编辑器全部内容
function plainTxt(EditorOrId){
	var Editor;
	if(Object.prototype.toString.call(EditorOrId) === "[object String]"){
		Editor=UE.getEditor(EditorOrId)
	}else{
		Editor=EditorOrId;
	}
	var Txt="";
	 Editor.ready(function() {
		 Txt= Editor.getContent();
		    });
		
	return Txt;
	 
}  

//获取百度编辑器纯文本内容
function editorText(EditorOrId){
	  var Text="";
	  var Editor;
		if(Object.prototype.toString.call(EditorOrId) === "[object String]"){
			Editor=UE.getEditor(EditorOrId)
		}else{
			Editor=EditorOrId;
		}
	  Editor.ready(function() {
	 Text=Editor.getContentTxt();
	    });
	
	return Text;
}

//获取编辑器带格式内容
function getTxt(EditorOrId){
	var  Txt="";
	 var Editor;
		if(Object.prototype.toString.call(EditorOrId) === "[object String]"){
			Editor=UE.getEditor(EditorOrId)
		}else{
			Editor=EditorOrId;
		}
	  Editor.ready(function() {
		  Txt= Editor.getPlainTxt();
			    });

	return Txt;
	
}  

//加载初始数据
function loadEditorText(EditorOrId,text,hint){
	var  Txt="";
	 var Editor;
		if(Object.prototype.toString.call(EditorOrId) === "[object String]"){
			Editor=UE.getEditor(EditorOrId)
		}else{
			Editor=EditorOrId;
		}
	  Editor.ready(function() {
		  Editor.setContent(text==null?"":text,false,true,hint);  //赋值给UEditor
	    });
	
};

//销毁百度编辑器
function deleteEditor(EditorOrId) {
	 var Editor;
		if(Object.prototype.toString.call(EditorOrId) === "[object String]"){
			Editor=UE.getEditor(EditorOrId)
		}else{
			Editor=EditorOrId;
		}
	Editor.destroy();
}

//禁止百度编辑器
var DisableEditor=function(editorName){
	
	UE.getEditor(editorName).setDisabled('fullscreen');
};

//百度编辑器可编辑
var EnableEditor=function(editorName){
	
	UE.getEditor(editorName).setEnabled();
};

var incompleteNum = 0;
var completeNum = 0;
//判断文本是否需要填写
/*id : 警告将会显示在此id标签前面
 * 调用 ：   warn("#id",str);
 * */
function warn(id,str){
	var html="";
	if(str==""||str=="null" || str==null ){
		html='<span class="hintico"></span>';
		incompleteNum++;
	}else{
		html='<span class="rightico"></span>';
		completeNum++;
	}
	$(id).prev().remove();
	$(id).before(html);
}
//判断文本是否需要填写
/*id : 警告将会显示在此id标签前面
 * 调用 ：   warn("#id",false);
 * */
function warnbool(id,bool){
	var html="";
	if(bool!=true){
		html='<span class="hintico"></span>';
		incompleteNum++;
	}else{
		html='<span class="rightico"></span>';
		completeNum++;
	}
	$(id).prev().remove();
	$(id).before(html);
}



//重新加载js id -> script标签id属性
var reloadJs = function(id){
    var jsObj = document.getElementById(id);
    var src = jsObj.src;
    delete jsObj;
    var script = document.createElement('script');
    script.src = src;
    document.body.appendChild(script);
};
//置顶 
//jsp 页面底部添加div：  <div class="srollbar-up-btn" style="display:none;" title="<spring:message code='sixthstep_back_to_top'/>"></div>
function  backToTop(){
	$(window).scroll(function () {
		if($(this).scrollTop()>$(window).height()){
			$(".srollbar-up-btn").show();
		}else{
			$(".srollbar-up-btn").hide();
		}
	})
	$('.srollbar-up-btn').bind('click', function(){
		$('body,html').animate({scrollTop: 0}, 'fast');
	})
	
}
/**
 * 清除课程进度缓存
 * @param courseId
 * @returns
 */
function cleanTreeRedis(courseId){
	$.ajax({
		 type:"post",
		 url:basePath+"/course/cleanTreeRedis",
		 data:{"courseId" : courseId},
	      dataType:'json',
	      success:function(data){
	    	}
	})
}
/**
 * <!--添加遮罩 -->
<div style=" z-index:10001;display: none;position: fixed;  top: 0px; left: 0px; right:0px;background-color: #777;  opacity: 0.6; "  id="bgDiv_zz"></div>
<!--添加遮罩 -->
 * @param div
 */

//打开遮罩 id ->遮罩层id
function showDetail(id){
	var bgDiv = document.getElementById(id);
    if("offsetwidth" in document.body){
	    bgDiv.style.width = document.body.offsetwidth + "px";
    }
	bgDiv.style.height = screen.height + "px";
	 bgDiv.style.display = "block";	
	
}
//关闭遮罩
function hideDetail(div){
  var bgDiv = document.getElementById(div);
		bgDiv.style.display =  "none";
}
function isInteger(obj) {
	 return Math.floor(obj) === obj;
}




/**
 * 优化火狐页面的跳转问题
 */
function firefoxPageJump(strClass){
	var browserName=getOs();
	$("."+strClass).live("click",function(event){
		if(browserName=="Firefox"){
			event.preventDefault();
			var newwindowHref = $(this).attr("href");
			var newWindowName = $(this).attr("target");
			MyWindow = window.open(newwindowHref,newWindowName);
			if(!MyWindow.closed){
				MyWindow.close();
			}
			MyWindow = window.open(newwindowHref,newWindowName);
			
		}
	})
}

//判断浏览器是否是IE
function isIEBrower() { //ie?
	 if (!!window.ActiveXObject || "ActiveXObject" in window){	 
		 return true;//是IE
	 }else{
		 return false;//不是IE
	 }  
}
//非IE浏览器使用console打印信息
function consoleTestInfo(str){
	if(!isIEBrower()){
		if(_debug){//debug模式下打印
			console.log(str);
		}
	}
}

/**
 * 判断浏览器
 * @returns {String}
 */
function getOs()  
{  
    var OsObject = "";  
   if(navigator.userAgent.indexOf("MSIE")>0) {  
        return "MSIE";  
   }  
   if(isFirefox=navigator.userAgent.indexOf("Firefox")>0){  
        return "Firefox";  
   }  
   if(isSafari=navigator.userAgent.indexOf("Safari")>0) {  
        return "Safari";  
   }   
   if(isCamino=navigator.userAgent.indexOf("Camino")>0){  
        return "Camino";  
   }  
   if(isMozilla=navigator.userAgent.indexOf("Gecko/")>0){  
        return "Gecko";  
   }  
     
}  

//限制输入正整数 obj->当前对象    min->最小值   max —>最大值   small-> 小数位数
function scoreValidation(obj,min,max,smallSize){
	$(obj).attr("maxlength",(max+"").length);
	var regular="^[0-9][0-9]*$";//判断是否为整数
	var $_num=obj.value;
	if($_num=="00"){
		 obj.value=0;
	}else{
		obj.value=$_num*1;
	};
	 var reg = /.*\..*/;
	if(smallSize!=null&&reg.test($_num)){//判断是否为小数
		 var  $_numArr = $_num.split(".");
			   var num1=$_numArr[1];
			   if($_numArr.length==3){//防止输入多个小数点
				   obj.value=$_num.substring(0,$_num.length-1);
				   return;
			   }
			   if(num1.length>0){
					regular="^[0-9]+(.[0-9]{"+smallSize+"})?$";//判断小数位数
					var temp = new RegExp(regular);
				  if(temp.test($_num)){
					  obj.value=$_num;
				  }else{
					  obj.value=$_num.replace(/[^\d.]/g,"").substring(0,$_num.length-1); 
				  }; 
			   };
			   $_num=$_numArr[0];
	};
	
	var temp = new RegExp(regular);
	if(!temp.test($_num)){//判断是否为整数
		obj.value='';
		}else{
			if((min*1>$_num*1||$_num*1>max*1)&&(min!=null||max!=null)){//限制范围
				obj.value=$_num.substring(0,$_num.length-1);
				
			}
		}	
}

